export default {
  get (cookieName) {
    let reg = '(^| )' + cookieName + '=([^;]*)(;|$)'
    let arr = document.cookie.match(new RegExp(reg))
    if (arr && arr instanceof Array && arr.length > 0) {
      return arr[2]
    }
    return null
  },
  set (cname, cvalue, exdays) {
    let d = new Date()
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000))
    let expires = 'expires=' + d.toUTCString()
    document.cookie = cname + '=' + cvalue + '; ' + expires
  },
  clear (name) {
    this.set(name, '', -1)
  },
  clearToken () {
    this.clear('token')
  },
  getToken () {
    return this.get('token')
  }
}
